home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ELECTRON / 1085.ZIP / FIRPLOT.ARC / README.FIR < prev   
Text File  |  1988-04-01  |  11KB  |  253 lines

  1.  
  2.  
  3.  
  4. Firplot is a program which calculates the filter coefficients for
  5. Finite Impulse Response (FIR) digital filters.  It will run on all
  6. PC-type computers.
  7.  
  8. If you intend to use FIRPLOT for serious work, rather than with
  9. the reduced capability of this version, use the order blank at the
  10. end of this file.  The advantage of having the full 128 stage
  11. capability is shown by examples in this file.
  12.  
  13.               Paul Selwa
  14.               61 East Tilden Dr.
  15.               Brownsburg, Indiana  46112
  16.  
  17.  
  18. FIR FILTERS.
  19.  
  20. There are various types of digital filters.  Of these the Finite
  21. Impulse Response (FIR) filter is the most useful.  It is
  22. unconditionally stable and has guaranteed linear phase response.
  23. It is resistant to the effects of noise and is the least sensitive
  24. type of digital filter to the effects of the precision (length) of
  25. the filter coefficients.
  26.  
  27.  
  28. CONSTRUCTION OF FIR DIGITAL FILTERS.
  29.  
  30. An FIR filter consists of the following components, some of which
  31. can exist in hardware or in software.
  32.  
  33. 1.  A low pass filter (LPF) to limit the bandwidth of the signal.
  34.     It is called an anti-alaising filter.
  35.  
  36. 2.  An analog-to-digital converter (ADC).  It may need to be
  37.     preceded by a sample and hold circuit if its conversion time
  38.     is long.
  39.  
  40. 3.  A data memory which saves the digitized samples of the signal
  41.     which is being processed.  Data is usually put into two's
  42.     complement form to be compatible with most multipliers.
  43.  
  44. 4.  A set of filter coefficients which are used to multiply the
  45.     data memory's samples.  These are usually in two's complement
  46.     (2C) form.
  47.  
  48. 5.  An accumulator which contains the sum-of-product terms which
  49.     are generated by multiplying the data memory contents by the
  50.     filter coefficients.
  51.  
  52. 6.  A multiplier chip, or a processor with multiplying capability.
  53.  
  54. 7.  A digital to analog converter (DAC) to change the filter's
  55.     output to an analog signal.
  56.  
  57. 8.  A low pass filter to remove noise from the output.  It is
  58.     called a reconstruction filter and passes the same frequency
  59.     components as does the anti-alaising filter.
  60.  
  61.  
  62. ALAISING:
  63.  
  64. Any digital filter has a bandwidth limitation which is set by the
  65. sampling rate of the input ADC which must be at least twice the
  66. bandwidth of the anti-alaising filter.  The folding frequency is
  67. defined as exactly one-half of the sampling rate and is
  68. theoretically the maximum frequency which the filter can handle
  69. without alaising problems.  When a signal is being sampled at a
  70. given rate, the signal's components are duplicated above and below
  71. each harmonic of the sampling frequency, just as they would appear
  72. as sidebands from an AM transmitter operating at the sampling
  73. frequency.  If you have a sampling rate of 10000 Hz and a signal
  74. of 1000 Hz you would get spurious outputs from the sampler at 9000
  75. Hz, (10000- 1000 Hz), and at 11000 Hz, (10000+1000 Hz), in
  76. addition to the baseband signal of 1000 Hz.  If the input signal's
  77. frequency was raised to 4999 Hz the sampler would produce sideband
  78. components at 5001 Hz, at 14999 Hz as well as the 4999 Hz baseband
  79. signal.  Clearly, the crossover point between the baseband signal
  80. and the lower sideband image of it will occur at one-half of the
  81. sampling rate.  Input signals of frequency greater than the
  82. folding frequency will appear as aliases of lower frequency
  83. signals.
  84.  
  85. FILTER COEFFICIENTS.
  86.  
  87. The stored data samples are all multiplied by the filter's
  88. coefficients, (also called filter taps), one-for-one in between
  89. the acquisition of each successive data sample.  The product of
  90. each of the multiply operations is accumulated and this sum-of-
  91. products result is a data word which is the filter's output until
  92. the next output value is calculated.
  93.  
  94. The program first calculates a coefficient set for a filter having
  95. unity gain (0 dB).  While these tap weights will produce a working
  96. filter, the set of numbers may not use the full 8 or 16 bit
  97. capability of the processor you are building unless your hardware
  98. can handle floating point math.  After finding the tap weights for
  99. the 0 dB filter, the program finds the largest valued coefficient
  100. and linearly scales all of them to gain the best use of fixed
  101. point hardware's mathematical range.  These results are printed in
  102. decimal and in 2C hexadecimal notation which has been scaled for a
  103. 16 bit machine.
  104.  
  105. The value of a 2C tap from the program will be equal to:
  106.  
  107.        -1*(sign bit) + (positive value of the remaining bits)
  108.  
  109. with the left-most remaining bit having a value of +0.5, the next
  110. having a value of +0.25 and so on.
  111.  
  112.  
  113. OPERATION OF AN FIR FILTER.
  114.  
  115. Suppose you need a length 5 FIR filter.  To make for easy notation
  116. I will refer to the data samples as D1-Dx, to the coefficients as
  117. C(1)-C(5).  and to the outputs as  O1-Ox.  After the fifth data
  118. sample is taken, the first useable output sample is produced.  The
  119. outputs prior to then will be unpredictable and you may want to
  120. mute the output until then.
  121.  
  122.             O1 = D1*C(5) + D2*C(4) + D3*C(3) + D4*C(2) + D5*C(1)
  123.  
  124. The output value O1 is placed in the output DAC.  Calculation is
  125. then halted until the 6th data sample appears. It replaces the
  126. first sample, and then the second output is calculated. In all
  127. cases, the new data sample replaces the oldest stored data sample.
  128.  
  129.             O2 = D2*C(5) + D3*C(4) + D4*C(3) + D5*C(2) + D6*C(1)
  130.  
  131. Output sample O2 is placed into the output DAC. Again the filter
  132. waits for the next data sample (which replaces the second sample),
  133. and then calculates the third output sample.
  134.  
  135.             O3 = D3*C(5) + D4*C(4) + D5*C(3) + D6*C(2) + D7*C(1).
  136.  
  137. This process is continued, and the filter produces outputs at the
  138. same rate as the incoming samples.
  139.  
  140. OUTPUT DATA PROCESSING:
  141.  
  142. The multiplication of two 16 bit 2C words produces a 32 bit
  143. product in which two identical sign bits occur. You will take the
  144. top 16 bits as your result after you perform a left shift of one
  145. bit to remove the redundant sign bit that results from the
  146. multiplication of two 2C numbers.  Some multipliers will provide
  147. this function automatically.
  148.  
  149. The 2C result may have to be changed back to simple binary code
  150. for the output DAC.  This is easily accomplished by inverting the
  151. sign bit position of the sum-of-products.   This will shift the 2C
  152. number to a value between zero and the maximum value your data
  153. variable can achieve.
  154.  
  155. USING FIRPLOT:
  156.  
  157. Start the program by entering its name without the "EXE" file
  158. extension.  The program will prompt you for a file-name so it can
  159. store the filter's parameters on disk.  This file holds all of
  160. your entries and all program data outputs.
  161.  
  162.  THE PROGRAM DOES NOT CHECK FOR AN EXISTING FILE OF THE SAME NAME.
  163.            USE CAUTION IN NAMING THE DISK FILE !!!!!!!!!
  164.  
  165. PROGRAM INPUTS:
  166.  
  167. The number of bands is the total of the passbands plus the
  168. stopbands.  A simple lowpass filter requires an entry of 2.
  169.  
  170. The filter length is an integer between 3 and 128 inclusive, but
  171. the length parameter is restricted to a smaller number in this
  172. shareware version of FIRPLOT.
  173.  
  174. The band edges can be entered as decimal fractions of the sampling
  175. rate, or as frequency variables.  For the former mode the numbers
  176. represent fractions of the sampling rate which can be anything
  177. your hardware can handle.  If you enter band edges as real
  178. frequency values, the program will prompt you for the actual
  179. sampling rate.  There are several checks provided as you enter
  180. these parameters.  For example, if you enter the passband and
  181. stopband edges as fractions of the sampling rate, and you call for
  182. a band edge greater than the folding frequency, which is 0.5, the
  183. program will go back to the first band edge so you can enter them
  184. again.  Similarly, if you had chosen to enter the band edges in
  185. terms of frequency and one of them is of a frequency greater than
  186. the folding frequency, the program will back up to the start of
  187. the routine.  This feature allows for easy escape from an error in
  188. band edge definition without going back to the start of the
  189. program.  In addition, if a valid band edge was entered out of
  190. sequence the program also returns to the start of the band edge
  191. entry routine.
  192.  
  193. You will enter parameters which define the bands as passbands or
  194. as stopbands.  In that way you define lowpass, highpass, bandpass
  195. and notch filters.
  196.  
  197. The final parameter is the RELATIVE ripple in the bands.  These
  198. are basically Chebyshev filters, but this is not the dB value of
  199. the ripple. It is the ratio of the ripple values in the filter's
  200. bands.  The actual ripple values are minimized by the program.
  201.  
  202. PROGRAM OUTPUTS:
  203.  
  204. The program starts computing the filter's taps after the relative
  205. ripple values are chosen.  The execution time is mainly
  206. proportional to the filter's length.  A 128 tap filter can easily
  207. take 15-20 minutes on a computer without a co-processor.  In
  208. general, a co-processor will cut the time by 80%.  Run time is not
  209. linearly related to filter length.  Short filters will run in
  210. seconds.  The program will automatically use a co-processor if
  211. there is one in the system.
  212.  
  213. The first output list is the impulse response of the filter.  It
  214. is named that because if a single data sample with a value of 1
  215. was fed into the filter, preceded and followed by zeros, the
  216. "impulse response" would show outputs equal to the filter's
  217. coefficients.  The next list is a version of the impulse response,
  218. which is scaled to force the maximum of the impulse response's
  219. absolute values to fall as close as possible to "-1" if the
  220. largest coefficient was negative, or to "+1-(one LSB of a 16 bit
  221. binary 2C number)" if the largest absolute value was a positive
  222. number.  The gain change that this causes in the filter's output
  223. level is printed at the top of the scaled impulse response
  224. listing.
  225.  
  226. The accompanying two's complement hex listing is based on a 16 bit
  227. fixed point hardware system.  If you want to use a smaller operand
  228. pick the number of bits you wish, starting with the MSB of the hex
  229. number.
  230.  
  231. The next output data is a list of the filter's gain as a function
  232. of frequency.  Its resolution is in steps of 0.05*(sampling rate).
  233.  
  234. The filter's gain data is plotted and is stored on disk.  First,
  235. in a compressed form which fits on the CRT and provides you with a
  236. quick look at the filter's response curve,  and second, in 1 dB
  237. resolution if you request that output.  The 1 dB plot is optional
  238. because it will also go to the disk well as to the CRT and really
  239. eats up disk space.  The detailed plot contains characters to
  240. indicate the direction of amplitude changes since high order
  241. filters have stopband nulls that are very close together.
  242.  
  243. PROBLEMS.
  244.  
  245. There are conditions you can ask for that the program cannot
  246. handle.  These are usually in terms of extremely sharp cutoff
  247. requirements and will cause either a divide by zero error, or in a
  248. failure to converge to a mathematical solution.  The first type of
  249. error will be flagged by your operating system, and the second by
  250. the filter design program.  There are no known problems in the
  251. program, and it is based on a well proven algorithm.
  252.  
  253. EXAMPLES: